package com.ruoyi.api.controller.user;

import com.ruoyi.api.annotation.CurrentUser;
import com.ruoyi.api.annotation.IgnoreAuth;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.HyUser;
import com.ruoyi.system.service.IHyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author 用户API
 * @date 2021-06-03 18:34
 */
@RestController
@RequestMapping("/api/user")
public class ApiUserController extends BaseController {

	@Autowired
	private IHyUserService userService;


	@GetMapping("/get")
	public AjaxResult get(@CurrentUser HyUser user) {

		return AjaxResult.success(user);
	}


	@IgnoreAuth
	@GetMapping("/get/{userId}")
	public AjaxResult get(@PathVariable("userId") Integer userId) {
		HyUser user = userService.getById(userId);
		return AjaxResult.success(user);
	}

	@PutMapping("/edit")
	public AjaxResult edit(@RequestBody HyUser user) {
		userService.updateById(user);
		return AjaxResult.success(user);
	}

	@PutMapping("/changeAvatar")
	public AjaxResult changeAvatar(@CurrentUser HyUser user, @RequestBody Map<String, String> params) {
		user.setAvatar(params.get("avatar"));
		userService.updateById(user);
		return AjaxResult.success(user);
	}
}
